package com.example.demo.service.impl;

import com.example.demo.entity.Player;
import com.example.demo.repository.PlayerRepository;
import com.example.demo.service.PlayerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class PlayerServiceImpl implements PlayerService {

    @Autowired
    private PlayerRepository playerRepository;

    // 查询所有球员
    public List<Player> getAllPlayers() {
        return playerRepository.findAll();
    }

    // 根据ID查询球员
    public Optional<Player> getPlayerById(Long id) {
        return playerRepository.findById(id);
    }

    // 新增或更新球员
    public Player savePlayer(Player player) {
        return playerRepository.save(player);
    }

    // 删除球员
    public void deletePlayerById(Long id) {
        playerRepository.deleteById(id);
    }
}